﻿using System;

namespace Products.Databases
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>
    /// Code 
    /// new Table=
    /// </remarks>
    [Serializable]
    public class Table : DatabaseObject
    {
        protected Table()
        {
        }

        public Table(Product product)
        {
            if (product == null)
                throw new ArgumentNullException("product");
            Product = product;
        }

        private string _conceptName;
        public virtual string ConceptName
        {
            get
            {
                if (String.IsNullOrEmpty(_conceptName))
                    return this.Name;
                return _conceptName;
            }
            set { _conceptName = value; }
        }

        public Table(Product product, ProductVersion productVersion)
            : base(productVersion)
        {
            if (product == null)
                throw new ArgumentNullException("product");
            Product = product;
        }


        public virtual Product Product { get; private set; }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="productVersion"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        protected override ISnapShot CreateNewStateChange(ProductVersion productVersion, ActionType content)
        {
            return new TableSnapshot(productVersion, content);
        }

        public virtual Field CreateField(ProductVersion productVersion)
        {
            var result = new Field(productVersion, this);
            return result;
        }
    }
}